package vmr

import (
	"fmt"
	"git.supremind.info/product/box/vehicle/global"
	"git.supremind.info/product/box/vehicle/internal/util"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"log"
	"net/http"
)

type Service struct {
	db *gorm.DB
}

func InitHttp(r *gin.RouterGroup, db *gorm.DB) {
	s := &Service{
		db: db,
		//client: vmr_client.InitVmrClient(global.VmrSetting.Host),
	}

	router := r.Group("/vmr/model")

	router.GET("/boxInfo", s.getBox)
	router.GET("/ipv4", s.queryIpv4)
	router.GET("/camera", s.getCamera)
	router.GET("/camera/status", s.getCameraStatus)
	router.GET("/task", s.getTask)
	router.GET("/extra", s.getExtraData)
	router.GET("/side_camera/config", s.getSideCameraConfig)
	router.GET("/side_camera/exposure", s.sideCameraExposure)
	router.GET("/service/status", s.getServiceStatus)

	router.PUT("/updateBox", s.updateBox)
	router.PUT("/camera/:location_type", s.setCamera)
	router.PUT("/task", s.task)
	router.PUT("/extra", s.setExtraData)
	router.PUT("/side_camera/config", s.sideCameraConfig)

	router.POST("/ipv4", s.updateIpv4)
	router.POST("/side_camera/capture", s.sideCameraCapture)
	router.POST("/service/start", s.startService)
	router.POST("/service/stop", s.stopService)
}

func (s *Service) startService(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) stopService(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getServiceStatus(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) sideCameraExposure(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getSideCameraConfig(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getExtraData(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) sideCameraCapture(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) sideCameraConfig(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) setExtraData(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getTask(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) task(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getCameraStatus(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getCamera(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) setCamera(c *gin.Context) {
	locationType := c.Param("location_type")
	c.JSON(http.StatusOK, locationType)
}

func (s *Service) updateIpv4(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) updateBox(c *gin.Context) {
	c.JSON(http.StatusOK, "SSSS")
}

func (s *Service) getBox(c *gin.Context) {
	var b = BoxInfo{}
	url := fmt.Sprintf("%s/v1/box", global.VmrSetting.Host)
	err := util.GetJson(c, url, &b)
	if err != nil {
		log.Println(err)
	}
	c.JSON(http.StatusOK, b)
}

func (s *Service) queryIpv4(c *gin.Context) {
	//result, _ := s.client.QueryIpv4(c)
	//c.JSON(http.StatusOK, result)
}
